package com.jds.test.bio.p12;

/**
 * https://www.cnblogs.com/silyvin/articles/12078621.html
 * https://www.cnblogs.com/silyvin/articles/12083466.html
 * Created by joyce on 2019/11/26.
 */
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.atomic.AtomicInteger;

public class Server {

    public static final int PORT = 12123;
    private static AtomicInteger atomicInteger = new AtomicInteger(0);

    public static void main(String [] f) throws IOException {
        new Server().server();
    }

    /**
     * single socket + socket and file
     * print 4059 稳定
     * lsof -p 12534 |wc -l 4138 稳定
     * @throws IOException
     */
    public void server() throws IOException {

        ServerSocket ss = new ServerSocket(PORT);
        while(true) {
            Socket s = ss.accept();

            // 连接成功后计数
            System.out.println(atomicInteger.incrementAndGet());

        }
    }
}